///////////////////////////////////////////////////
// Election Administration Polarization
// Check Bandwidth Sensitivity
///////////////////////////////////////////////////

gl path "~/Library/CloudStorage/GoogleDrive-danmckinleythompson@gmail.com/My Drive/ElecAdminPolarization/How_Partisan_Is_Local_Election_Admin_Replication"


* Bring in the presidential election analysis data
use "$path/analysis_data/rd_election_analysis_data.dta", clear

* Loop over 25 different bandwidths and store the RD estimate
matrix B = J(25, 3, .)
forval b = 1/25 {
	reg r_oos_state_year_vs_dem treat rv treat_rv if abs(rv)<`b'/100 & office=="pres", vce(clust election_id)
	matrix B[`b',1] = _b[treat]
	matrix B[`b',2] = _b[treat] + 1.96*_se[treat]
	matrix B[`b',3] = _b[treat] - 1.96*_se[treat]
}

* Plot the coefficients across bandwidths
svmat B
rename (B1-B3) (coef upper lower)
gen bandwidth = _n/100
twoway (connected coef bandwidth if bandwidth<=.25, mc(gs2) lc(gs2)) ///
	(line lower bandwidth if bandwidth<=.25, lc(gs10) lp(dash)) ///
	(line upper bandwidth if bandwidth<=.25, lc(gs10) lp(dash)), ///
	xti("Bandwidth") yti("Effect on Dem Pres Vote Share") yline(0) ///
	graphregion(color(white)) legend(off)
graph export "$path/output/rd_dem_pres_vs_bw_diff.pdf", replace
